home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / twnsck12.zip / SRC\TWINSOCK.H < prev    next >
C/C++ Source or Header  |  1994-11-20  |  3KB  |  162 lines

  1. /*
  2.  *  TwinSock - "Troy's Windows Sockets"
  3.  *
  4.  *  Copyright (C) 1994  Troy Rollo <troy@cbme.unsw.EDU.AU>
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. enum    arg_type
  22. {
  23.     AT_Int16 = 1,
  24.     AT_Int32,
  25.     AT_Int16Ptr,
  26.     AT_Int32Ptr,
  27.     AT_Char,
  28.     AT_String,
  29.     AT_GenPtr,
  30. #ifdef __MSDOS__
  31.     AT_Int = AT_Int16,
  32.     AT_IntPtr = AT_Int16
  33. #else
  34. #ifdef apollo
  35. #define    AT_Int AT_Int32
  36. #define    AT_IntPtr AT_Int32
  37. #else
  38.     AT_Int = AT_Int32,
  39.     AT_IntPtr = AT_Int
  40. #endif
  41. #endif
  42. };
  43.  
  44. enum    Functions
  45. {
  46.     FN_Init = 0,
  47.     FN_Accept,
  48.     FN_Bind,
  49.     FN_Close,
  50.     FN_Connect,
  51.     FN_IOCtl,
  52.     FN_GetPeerName,
  53.     FN_GetSockName,
  54.     FN_GetSockOpt,
  55.     FN_Listen,
  56.     FN_Select,
  57.     FN_Send,
  58.     FN_SendTo,
  59.     FN_SetSockOpt,
  60.     FN_Shutdown,
  61.     FN_Socket,
  62.     FN_Data,
  63.     FN_GetHostName,
  64.         FN_HostByAddr,
  65.         FN_HostByName,
  66.         FN_ServByPort,
  67.         FN_ServByName,
  68.         FN_ProtoByNumber,
  69.         FN_ProtoByName
  70. };
  71.  
  72. struct    func_arg
  73. {
  74.     enum arg_type    at;
  75.     void        *pvData;
  76.     int        iLen;
  77. #ifdef    _Windows
  78.     BOOL        bConstant;
  79. #endif
  80. };
  81.  
  82. struct    transmit_function
  83. {
  84.     enum    Functions    fn;
  85.     int            nArgs;
  86.     struct    func_arg    *pfaList;
  87.     struct    func_arg    *pfaResult;
  88. };
  89.  
  90. #define    MAX_HOST_ENT    1024
  91. #define    MAX_ALTERNATES    20
  92.  
  93. #ifdef _Windows
  94. struct    data
  95. {
  96.     int    iLen;
  97.     int    nUsed;
  98.     struct    sockaddr_in sin;
  99.     char    *pchData;
  100.     struct    data *pdNext;
  101. };
  102.  
  103. struct    per_task
  104. {
  105.     HTASK            htask;
  106.     char            achAddress[16];
  107.     struct    per_task    *pptNext;
  108.     int            iErrno;
  109.     FARPROC            lpBlockFunc;
  110.     BOOL            bCancel;
  111.     BOOL            bBlocking;
  112.     struct    hostent        he;
  113.     struct    servent        se;
  114.     struct    protoent    pe;
  115.     char            achHostEnt[MAX_HOST_ENT];
  116.     char            *apchHostAlii[MAX_ALTERNATES];
  117.     char            *apchHostAddresses[MAX_ALTERNATES];
  118.     char            achServEnt[MAX_HOST_ENT];
  119.     char            *apchServAlii[MAX_ALTERNATES];
  120.     char            achProtoEnt[MAX_HOST_ENT];
  121.     char            *apchProtoAlii[MAX_ALTERNATES];
  122. };
  123.  
  124. struct    per_socket
  125. {
  126.     SOCKET            s;
  127.     unsigned short        iFlags;
  128.     struct    data        *pdIn;
  129.     struct    data        *pdOut;
  130.     HTASK            htaskOwner;
  131.     struct    per_socket    *ppsNext;
  132.     long            iEvents;
  133.     HWND            hWnd;
  134.     unsigned        wMsg;            
  135. };
  136.  
  137. #define    PSF_ACCEPT    0x0001
  138. #define    PSF_CONNECT    0x0002
  139. #define    PSF_SHUTDOWN    0x0004
  140. #define    PSF_NONBLOCK    0x0008
  141. #define    PSF_CLOSED    0x0010
  142.  
  143. #define    INIT_ARGS(args, type, data, size) \
  144.         ( args.at = type, \
  145.           args.pvData = (void *) data, \
  146.           args.iLen = size, \
  147.           args.bConstant = FALSE )
  148.  
  149. #define INIT_CARGS(args, type, data, size) \
  150.         ( args.at = type, \
  151.           args.pvData = (void *) data, \
  152.           args.iLen = size, \
  153.           args.bConstant = TRUE )
  154.  
  155. #define    INIT_TF(tf, func, count, args, retval) \
  156.         ( tf.fn = func, \
  157.           tf.nArgs = count, \
  158.           tf.pfaList = args, \
  159.           tf.pfaResult = &retval )
  160.  
  161. #endif
  162.